package com.sinya.shoppingmall.ui.recomend;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sinya.shoppingmall.R;

/**
 * @author KoizumiSinya
 * @date 2015/12/25.
 */
public class MenuItemView extends LinearLayout {

    private Context mContext;
    private View rootView;
    private int itemId;

    private onMenuItemClickListener onLayoutClick;

    public MenuItemView(Context context) {
        super(context);
        this.mContext = context;
        rootView = View.inflate(mContext, R.layout.view_menu_item, null);
        this.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 1));
        this.addView(rootView);
    }

    public void setView(int id, int imageRes, String name, final onMenuItemClickListener onLayoutClick) {
        this.itemId = id;
        this.setClickable(true);
        this.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onLayoutClick != null) {
                    onLayoutClick.onMenuClick(itemId);
                }
            }
        });
        ImageView img = (ImageView) rootView.findViewById(R.id.img_icon);
        img.setImageResource(imageRes);

        TextView tv = (TextView) rootView.findViewById(R.id.tv_name);
        tv.setText(name);
    }


    public interface onMenuItemClickListener {
        public void onMenuClick(int id);
    }
}
